package cq.zhcqk.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;
import java.util.Map;

import cq.zhcqk.R;
import cq.zhcqk.util.Common;
import cq.zhcqk.util.ImageLoaderHelper;
import cq.zhcqk.util.StringUtil;

/**
 * Created by zhangle on 2017/12/9.
 */
public class DyxxAdapter extends BaseAdapter{
    List<Map<String, Object>> list;
    Context context;
    public DyxxAdapter(Context context, List<Map<String, Object>> list){
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list ==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final viewHolder holder;
        if(convertView == null){
            holder = new viewHolder();
            convertView = View.inflate(context, R.layout.item_list_dyxx,null);
            holder.dyxx_title = (TextView) convertView.findViewById(R.id.dyxx_title);
            holder.dyxx_pop = (TextView) convertView.findViewById(R.id.dyxx_pop);
            holder.dyxx_time = (TextView) convertView.findViewById(R.id.dyxx_time);
            convertView.setTag(holder);
        }else{
            holder = (viewHolder) convertView.getTag();
        }

        Map<String, Object> info = list.get(position);
        holder.dyxx_title.setText(info.get("title")+"");
        holder.dyxx_pop.setText(StringUtil.stringToInt(info.get("studynum")+"")+"人");
        holder.dyxx_time.setText(StringUtil.stringToInt(info.get("totaltime")+"")+"小时");
        return convertView;
    }

    private class viewHolder{
        private TextView dyxx_title;
        private TextView dyxx_pop;
        private TextView dyxx_time;
    }
}
